
import { hexMD5 } from './../common/js/MD5';

let baseURLPost = 'http://192.168.5.101/miniprogram/';//post数据请求接口(测试环境)
let baseURL = 'http://192.168.5.101:8080/portal/';//get请求数据和上传文件接口API(测试环境)


//let baseURLPost = 'http://www.yjwh.shop/miniprogram/'//【线上环境】
//let baseURL ='http://www.yjwh.shop/miniprogram/';//【线上环境】


// https://www.yjwh.shop/miniprogram/


// let baseURL ='https://www.yjwh.shop/miniprogram/';
// let baseURL ='http://47.94.218.214:8088/portal/';
  // url: "http://192.168.5.101:8080/portal/",
  // url:"https://www.yjwh.shop/miniprogram/",
  // url:"http://47.94.218.214:8088/portal/",

// 请求数据公共函数
  function requestData (options) {
 	var src = "1",
    timestamp = new Date().getTime(),
      token = sessionStorage.getItem("token"),
 		id = sessionStorage.getItem("userID");
 		 token=token=="null"?" ":JSON.parse(token)
 		 id=id=="null"?" ":JSON.parse(id)
    let params={
    	baseURL:baseURL+options.url,
    	params:{
    	callback:"jq_1234567890",
    	src:src,
    	token:token,
    	userId:id,
    	timestamp:timestamp,
    	md5:hexMD5(src+timestamp+"055B%HeGZ5V@Qoec"),
    	msg:options.msg
    }
    }
    return params 
 }

  function requestDataPost (options) {
  var src = "1",
    timestamp = new Date().getTime(),
      token = sessionStorage.getItem("token"),
    id = sessionStorage.getItem("userID");
     token=token=="null"?" ":JSON.parse(token)
     id=id=="null"?" ":JSON.parse(id)
    let params={
      baseURL:baseURLPost+options.url,
      params:{
      src:src,
      token:token,
      userId:id,
      timestamp:timestamp,
      md5:hexMD5(src+timestamp+"055B%HeGZ5V@Qoec"),
      msg:options.msg
    }
    }
    return params 
 }
 // 截取返回数据字符串函数
function cutString(data){
	return JSON.parse(data.slice(data.indexOf("(")+1,data.lastIndexOf(")")))
}

 module.exports = {
  sendData: requestData,
  sendDataPost:requestDataPost,
  cutString:cutString,
  baseURL:baseURL
}
 